/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { HttpSrv } from 'lfun-bg-comp';
import { ImportParams } from '..';

/* 关键信息 */
export interface PlanningSchoolKeyInfo {
  id: any;
  planning_school_name: string;
  planning_school_no: string;
  borough: string;
  block: string;
  planning_school_level: string;
  planning_school_org_type: string;
  planning_school_operation_type: string;
  planning_school_operation_type_lv2: string;
  planning_school_operation_type_lv3: string;
}
/* 查询规划校 */
export interface SearchPlanningSchool {
  planning_school_name: string;
  founder_type: any;
  founder_type_lv2: any;
  founder_type_lv3: any;
  borough: string;
  block: string;
  status: string;
  planning_school_code: string;
  planning_school_level: string;
  process_code?: 'p_school_open' | 'p_school_close' | 'p_school_keyinfo_change';
}
/* 创建规划校 */
export interface CreatePlanningSchool {
  planning_school_name?: string;
  planning_school_no?: string;
  block?: string;
  borough?: string;
  planning_school_type?: string;
  planning_school_edu_level?: string;
  planning_school_category?: string;
  planning_school_operation_type?: string;
  planning_school_org_type?: string;
  planning_school_level?: string;
}
/* 关闭规划校 */
export interface ClosePlanningSchool {
  planning_school_id: string;
  action_reason: string;
  related_license_upload: string[];
}
// 基本信息、通讯信息、学校信息
export interface PlanningSchoolInfo {
  planning_school: {
    id?: string;
    planning_school_name?: string;
    planning_school_short_name?: string;
    planning_school_code?: string;
    create_planning_school_date?: string;
    planning_school_closure_date?: string;
    founder_type: string;
    founder_type_lv2: string;
    founder_type_lv3: string;
    founder_name?: string;
    urban_rural_nature?: string;
    planning_school_operation_type?: string;
    planning_school_org_form?: string;
    planning_school_operation_type_lv2?: string;
    planning_school_operation_type_lv3?: string;
    department_unit_number?: string;
    sy_zones?: string;
    historical_evolution?: string;
    status?: string;
  };
  planning_school_communication: {
    id?: string;
    planning_school_id?: string;
    postal_code?: string;
    fax_number?: string;
    email?: string;
    contact_number?: string;
    area_code?: string;
    long?: string;
    lat?: string;
    leg_repr_name?: string;
    party_leader_name?: string;
    party_leader_position?: string;
    adm_leader_name?: string;
    adm_leader_position?: string;
    loc_area?: string;
    loc_area_pro?: string;
    detailed_address?: string;
    related_license_upload?: string;
    school_web_url?: string;
  };
  planning_school_eduinfo: {
    id?: string;
    planning_school_id?: string;
    is_ethnic_school?: boolean;
    is_att_class?: boolean;
    att_class_type?: boolean;
    is_province_feat?: boolean;
    is_bilingual_clas?: boolean;
    minority_lang_code?: boolean;
    is_profitable?: boolean;
    prof_org_name?: string;
    is_prov_demo?: boolean;
    is_latest_year?: boolean;
    is_town_kinderg?: boolean;
    is_incl_kinderg?: boolean;
    is_affil_school?: boolean;
    affil_univ_code?: boolean;
    affil_univ_name?: boolean;
    is_last_yr_revok?: boolean;
    is_school_counted?: boolean;
  };
}
// 删除
export const deletePlanningSchool = planning_school_id =>
  HttpSrv().delete(`/school/v1/planningschool/?planning_school_id=${planning_school_id}`);
// 查询单个
export const getPlanningSchool = planning_school_id =>
  HttpSrv().get(`/school/v1/planningschool/`, { params: { planning_school_id } });
// 新增
export const createPlanningSchool = (params: CreatePlanningSchool) =>
  HttpSrv().post('/school/v1/planningschool/', params);
// 修改
export const updatePlanningSchool = (planning_school_id, info: PlanningSchoolInfo) =>
  HttpSrv().put(`/school/v1/planningschool/?planning_school_id=${planning_school_id}`, info);
//规划校查询 todo: 这个不知道干嘛用的 /api/school/v1/planningschool/search
export const searchPlanningSchoolByName = (planning_school_name: string, page = 1, per_page = 100) =>
  HttpSrv().get(`/school/v1/planningschool/search`, { params: { planning_school_name, page, per_page } });
export const getPlanningSchoolById = planning_school_id =>
  HttpSrv().get(`/school/v1/planningschool/?planning_school_id=${planning_school_id}`);

// 分页查询
export const searchPlanningSchool = (params: SearchPlanningSchool, page: number, per_page: number) => {
  const arr = [];
  if (params.founder_type) {
    params.founder_type.forEach(item => {
      arr.push(`founder_type=${item}`);
    });
    delete params.founder_type;
  }
  if (params.founder_type_lv2) {
    params.founder_type_lv2.forEach(item => {
      arr.push(`founder_type_lv2=${item}`);
    });
    delete params.founder_type_lv2;
  }
  if (params.founder_type_lv3) {
    params.founder_type_lv3.forEach(item => {
      arr.push(`founder_type_lv3=${item}`);
    });
    delete params.founder_type_lv3;
  }
  return HttpSrv().get(`/school/v1/planningschool/page${arr && arr.length > 0 ? '?' : ''}${arr.join('&')}`, {
    params: { ...params, page, per_page },
  });
};
//todo: 这个不知道干嘛用的 /api/school/v1/planningschool/baseinfo
// 关闭
export const closePlanningSchool = (params: ClosePlanningSchool) =>
  HttpSrv().patch(`/school/v1/planningschool/close`, {}, { params: { ...params } });
// 开办规划学校
export const openPlanningSchool = (planning_school_id, info: PlanningSchoolInfo) =>
  HttpSrv().put(`/school/v1/planningschool/open?planning_school_id=${planning_school_id}`, info);
// 关键信息修改
export const updatePlanningSchoolKeyInfo = (info: PlanningSchoolKeyInfo) =>
  HttpSrv().put(`/school/v1/planningschool/keyinfo`, info);

export const planningSchoolCloseAudit = (process_instance_id: any, remark: string, is_approve: boolean) =>
  HttpSrv().patch(`/school/v1/planningschool/close-audit`, {
    process_instance_id,
    remark,
    transaction_audit_action: is_approve ? 'pass' : 'refuse',
  });
export const planningSchoolKeyinfoAudit = (process_instance_id: any, remark: string, is_approve: boolean) =>
  HttpSrv().patch(`/school/v1/planningschool/keyinfo-audit`, {
    process_instance_id,
    remark,
    transaction_audit_action: is_approve ? 'pass' : 'refuse',
  });
export const planningSchoolOpenAudit = (process_instance_id: any, remark: string, is_approve: boolean) =>
  HttpSrv().patch(`/school/v1/planningschool/open-audit`, {
    process_instance_id,
    remark,
    transaction_audit_action: is_approve ? 'pass' : 'refuse',
  });

export const importPlanningSchool = (params: ImportParams) =>
  HttpSrv().post(`/school/v1/planningschool/planning-school-import`, params);

export const getPlanningSchoolAudit = (params: SearchPlanningSchool, page: number, per_page: number) => {
  const arr = [];
  if (params.founder_type) {
    params.founder_type.forEach(item => {
      arr.push(`founder_type=${item}`);
    });
    delete params.founder_type;
  }
  if (params.founder_type_lv2) {
    params.founder_type_lv2.forEach(item => {
      arr.push(`founder_type_lv2=${item}`);
    });
    delete params.founder_type_lv2;
  }
  if (params.founder_type_lv3) {
    params.founder_type_lv3.forEach(item => {
      arr.push(`founder_type_lv3=${item}`);
    });
    delete params.founder_type_lv3;
  }
  return HttpSrv().get(
    `/school/v1/planningschool/planning-school-audit${arr && arr.length > 0 ? '?' : ''}${arr.join('&')}`,
    {
      params: { ...params, page, per_page },
    }
  );
};

export const getPlanningSchooWorkflowInfo = (apply_id: any) =>
  HttpSrv().get(`/school/v1/planningschool/planning-school-workflow-info`, { params: { apply_id } });
